package com.nf.service;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class MyTranscation implements InvocationHandler {

    private Object target;

    public MyTranscation(Object target){
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        Object o = null;
        try{
            System.out.println("con.setAutoCommit(false);");
            o = method.invoke(target, args);//执行银行业务
            System.out.println("con.commit();");
        }catch (Exception e){
            System.out.println("con.rollback();");
        }
        return o;
    }


//    public void beforeGo(){
//        System.out.println("con.setAutoCommit(false);");
//    }
//
//    public void afterGo(){
//        System.out.println("con.commit();");
//        System.out.println("con.rollback();");
//    }
}
